<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/1/24
 * Time: 16:05
 */
namespace common\sources\write\adminuser;

use common\models\craftsman\AdminUser;
use Yii;

class AdminUserAccess implements IAdminUserAccess
{
    public function delLoginUser($data)
    {
        return AdminUser::find()
            ->where(['id' => $data['login_id']])
            ->one()
            ->delete();
    }
    public function addLoginUser($data)
    {
        return Yii::$app->db->createCommand()->insert('admin_user', [
            'phone' => $data['account'],
            'username' => $data['username'],
            'email' => $data['email'],
            'role' => $data['role'],
            'create_time' => time()
        ])->execute();
    }
    public function modifyLoginUser($data)
    {
        $sql = 'UPDATE ' . AdminUser::tableName() . ' SET email = :email,username = :username,role = :role,
        update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':email' => $data['email'],
                ':username' => $data['username'],
                ':update_time' => time(),
                ':role' => $data['role'],
                ':id' => $data['login_id']
            ])->execute();
    }
}